/**
 * Created by Administrator on 2017/7/19.
 */
$(function () {
    // new ZoomPic("jswbox");
    $('.head-right li').hover(function () {
        // $(this).find("div").css("display","block");

    },function () {
        if(!$(this).hasClass('active')){
            // $(this).find("div").css("display","none");
        }
    });

//    回到顶部
    var index = $(document).scrollTop();
    checkScroll();
    // checkScroll();
    $(window).scroll(function () {
        index = $(document).scrollTop();
        checkScroll();
    });
    function checkScroll() {
        if(index > 100){
            $('.top').css("height","40px");
        }else {
            $('.top').css("height","0");
        }
    }

    $(".top").click(function () {
        $("html,body").animate({scrollTop:"0"},300);
        $(".head_fixed").slideUp(300);
    });
    $(".bottom-center ul li").hover(function () {
        $(this).find('a').css("color","white");
    },function () {
        $(this).find('a').css("color","black");
    });
    $(".contact").click(function () {
        $("html,body").animate({scrollTop:$(document).height()},500);
        $(".head_fixed").slideUp(200);
    });
    var _headFixedIndex;
    $(window).scroll(function () {
        _headFixedIndex = $(document).scrollTop();
    });
    _headFixedIndex = $(document).scrollTop();
//    页面滚动触发时间
    var scrollFunc = function (e) {
        var direct = 0;
        e = e || window.event;
        if (e.wheelDelta) {  //判断浏览器IE，谷歌滑轮事件
            if (e.wheelDelta > 0) { //当滑轮向上滚动时
                // alert("滑轮向上滚动");
                // $(".head_fixed").slideDown(500);
                if(_headFixedIndex<900){
                    $(".head_fixed").slideUp(200);
                }else {
                    $(".head_fixed").slideDown(300);
                }
            }
            if (e.wheelDelta < 0) { //当滑轮向下滚动时
                // alert("滑轮向下滚动");
                $(".head_fixed").slideUp(200);
            }
        } else if (e.detail) {  //Firefox滑轮事件
            if (e.detail< 0) { //当滑轮向上滚动时
                // alert("滑轮向上滚动");
                // $(".head_fixed").slideDown(500);
                if(_headFixedIndex<900){
                    $(".head_fixed").slideUp(200);
                }else{
                    $(".head_fixed").slideDown(300);
                }
            }
            if (e.detail> 0) { //当滑轮向下滚动时
                // alert("滑轮向下滚动");
                $(".head_fixed").slideUp(200);

            }
        }
        // ScrollText(direct);
    };
    //给页面绑定滑轮滚动事件
    if (document.addEventListener) {
        document.addEventListener('DOMMouseScroll', scrollFunc, false);
    }
    //滚动滑轮触发scrollFunc方法
    window.onmousewheel = document.onmousewheel = scrollFunc;

    function GetSlideDirection(startX, startY, endX, endY) {
        var dy = startY - endY;
        //var dx = endX - startX;
        var result = 0;
        if(dy>0) {//向上滑动
            result=1;
        }else{//向下滑动
            result=2;
        }

        return result;
    }

//滑动处理
    var startX, startY;
    document.addEventListener('touchstart',function (ev) {
        startX = ev.touches[0].pageX;
        startY = ev.touches[0].pageY;
    }, false);

    document.addEventListener('touchend',function (ev) {
        var endX, endY;
        endX = ev.changedTouches[0].pageX;
        endY = ev.changedTouches[0].pageY;
        var direction = GetSlideDirection(startX, startY, endX, endY);
        switch(direction) {
            case 0:
                break;
            case 1:
                // 向上
                // alert("up");
                $(".head_fixed").slideUp(200);
                break;
            case 2:
                // 向下
                if(_headFixedIndex<1000 ){
                    $(".head_fixed").slideUp(200);
                }else{
                    $(".head_fixed").slideDown(300);
                }
                break;

            default:
        }
    }, false);
//    链接跳转
    $(".lianjie li").click(function () {
        $(this).index();
       if($(this).index()==0){
           window.open("http://zhuti.xiaomi.com/search?title=%E4%B8%BB%E9%A2%98%E5%8C%85&keywords=for");
       }else if($(this).index()==1){
           window.open("http://theme.flyme.cn/themes/public/developers/299017/themes?publisher_name=For%E5%9B%A2%E9%98%9F&cate_type=theme&mzos=4.0");
       }else{
           window.open("http://www.emui.com/cn/plugin/hwtheme/theme");
       }
    });

    //邮箱hover特效
    $('.email').hover(function () {
        $('.email p').stop(true,false).animate({width:'199px'},500);
    },function () {
        $('.email p').hover(function () {
            $('.email p').stop(true,false).animate({width:'199px'},500);
        },function () {
            $('.email p').stop(true,false).animate({width:'0'},500);

        });
        $('.email p').stop(true,false).animate({width:'0'},500);

    })
});